<?php

namespace app\index\controller;
use think\Db;
use app\index\model\User as UserModel;
use app\index\model\Profile;
use think\Controller;
use think\Session;
use app\index\model\Account;
use app\index\model\Address;

class product extends Controller
{
    public function goods_product()
    {
        $data['username'] = session('name');
        $this->assign('data',$data);
        //查询表goods获取手机的具体品牌 型号 描述信息等属性
        $brand = Db::name('goods')->where('isalive',1)->order('reg_time desc' )->paginate(8);
        $this->assign("brand",$brand);  
        //查询表goodsimages某款手机的图片
        $pricture = Db::name('Goodsimages')->where('image_id',1)->select();
        $this->assign("pricture",$pricture);
        //原生查询表attr数据去除goods_id相同的值保留goods_id对应的id最小的一条数据即可  获取手机的具体颜色 制式 价格 库存等属性属
        $result = Db::query ('select * from ecmall_attr where id in (select min(id) from ecmall_attr group by goods_id)'); 
        $this->assign("result",$result);
        $this->view->engine->layout(true);

       //查询表goodsimages某款手机的图片
        $pricture = Db::name('Goodsimages')->where('image_id',1)->select();
        $this->assign("pricture",$pricture);  

        //查询品牌小米的手机前3条数据
        $xiaomi = Db::name('goods')->where('brand','小米')->order('reg_time asc')->limit(4)->select();
        //var_dump($brand);
        $this->assign("xiaomi",$xiaomi);
        
        //查询品牌华为的手机前4条数据
        $huawei  = Db::name('goods')->where('brand','华为')->order('reg_time desc')->limit(4)->select();
        //var_dump($brand);
        $this->assign("huawei",$huawei);

        //查询品牌oppo的手机前4条数据
        $oppo  = Db::name('goods')->where('brand','oppo')->order('reg_time desc')->limit(4)->select();
        //var_dump($brand);
        $this->assign("oppo",$oppo);
        return $this->fetch();

        
    }


}